<!-- 学生登录界面 -->
<template>
	<view class="login_container" v-if="loginSuccess" >
		<view class="form">
			<view class="inputname">
				<view class="name_box">姓名</view>
			    <input 
					v-model="name"  
					type="string"  
					placeholder="请输入姓名" />
			</view>
			<view class="underline"></view>
			
			<view class="inputnumber">
				<view class="number_box">学号</view>
				<input 
				    v-model="studentId"
					type="number" 
					placeholder="请输入学号" />
			</view>
			
			<view class="underline"></view>
	    </view>
		
		<view class="btn">
			<button class="btn" @click="confirm">确定</button>
		</view>
	</view>
	
</template>

<script>
	export default {
		data() {
			return {
				name: '',
				studentId:Number,
				mode:1,
				loginSuccess:true,
			}
		},
		onLoad(res){
			console.log("res",res)
			console.log(res.uuid)
			uni.setStorageSync("uuid",res.uuid)
		},
		methods: {
			 async confirm(){
				const valid= /^[0-9]+$/;
				const nameValid=/^[\s\S]*.*[^\s][\s\S]*$/;
				let studentIdValid=valid.test(this.studentId)
				let stunameValid=nameValid.test(this.name)
				
				if(!stunameValid) {
					 // 直接在这里判断
					 return uni.showToast({
						 title: '姓名不能为空',
						 icon: 'error',
					 })
				 }
				if(!studentIdValid) {
					 // 直接在这里判断
					 return uni.showToast({
						 title: '学号不正确',
						 icon: 'error',
					 })
				 }
				
				 let data = {
					stuName:this.name,
					 stuId:this.studentId
					
				 };
				 let _that=this;
				 const res=await this.$myRequest("/listname/insert","POST",data,function(res){
					debugger
					console.log("res.request",res)
					_that.loginSuccess=false,
					uni.showToast({
						title:'登陆成功',
						icon:"success"
					})
					uni.navigateTo({
						url:"/pages/index/success"
					})
				 })
			 },
			 
				
		}
	}
</script>

<style>

	.login_container{
		height:100%;
		width:100%;
		position:fixed;
		display:flex;
		justify-content: center;
		align-items: center;
		flex-direction: column;
	}
	.form{
		display:flex;
		margin-left: 10%;
		margin-bottom:10%;
		flex-direction: column;
	}
	.inputnumber,.inputname{
		font-size:30rpx;
		display:flex;
		align-items: center;
		flex-direction:row;
	}
	.underline{
		width:450rpx;
		height:50rpx;
		border-top: gainsboro 1rpx solid;
		
	}
	.name_box,.number_box{
		margin-bottom: 16rpx;
		margin-right: 130rpx;
	}
	button{
		background-color: steelblue;
		padding:0rpx 60rpx;
		text-align: center;
		font-size:30rpx;
		border-radius: 40rpx;
		color:white;
	}
	input{
		margin-bottom:15rpx;
	}
	

</style>
